/*
 * 	Copyright(C) 2010-2013 Baidu Group
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 */
package com.feiluan.util;


import io.netty.buffer.ByteBuf;


public class ChannelUtil {


    public static byte[] readChannelBufferAsByte(ByteBuf buffer) {
        byte[] bytes = new byte[buffer.readableBytes()];

        int i = 0;
        while (buffer.isReadable()) {
            bytes[i] = buffer.readByte();
            i++;
        }
        return bytes;
    }

    public static String readChannelBufferAsString(ByteBuf buffer) {
        byte[] bytes = readChannelBufferAsByte(buffer);
        return new String(bytes);
    }

}
